package com.yonyougov.devops.cruxcisupport.domain;


import java.math.BigInteger;

import com.yonyougov.devops.cruxcisupport.env.EnvEntity;
import com.yonyougov.devops.cruxcisupport.env.dto.EnvAddRequestDto;
import com.yonyougov.devops.fwc.api.dto.BaseResponseDto;
import com.yonyougov.devops.fwc.core.controller.CrudController;
import com.yonyougov.devops.fwc.core.service.BaseService;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/api/v2/domain")
public class DomainController extends CrudController<DomainEntity, BigInteger> {

    @Autowired
    private DomainService domainService;

    @Override
    public BaseService<DomainEntity, BigInteger> getService() {
        return domainService;
    }

    //<!--用户自定义代码开始-->
    @SneakyThrows
    @PostMapping(value = "/e/add")
    public BaseResponseDto addDomain (@RequestBody @Valid DomainEntity requestDto) {
        DomainEntity domainEntity = new DomainEntity();
        BeanUtils.copyProperties(requestDto,domainEntity);
        domainService.add(domainEntity);
        return BaseResponseDto.getSuccessInstance();
    }
    @PostMapping(value = "/e/one")
    public BaseResponseDto allDomain (@RequestBody @Valid DomainEntity requestDto) {
        DomainEntity domainEntity = new DomainEntity();
        BeanUtils.copyProperties(requestDto,domainEntity);
        DomainEntity domainEntity1 = domainService.findBy(domainEntity);
        BaseResponseDto result = BaseResponseDto.getSuccessInstance();
        result.put("totalCount",1);
        result.put("data",domainEntity1.getCode());
        return BaseResponseDto.getSuccessInstance();
    }
    //<!--用户自定义代码结束-->
}
